package Practice;

import java.util.Scanner;

public class PERKET {
    static int n;
    static int[] s;
    static int[] b;
    static int mindiff = Integer.MAX_VALUE;//表示int类型的最大类，相当于设置了一个最大的初始值

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        s = new int[n];
        b = new int[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        dfs(0,1,0,0);
        System.out.println(mindiff);
    }

    static void dfs(int index,int totals,int totalb,int selectnum){
        if (index == n){
            if (selectnum > 0){
                int diff = Math.abs(totalb - totals);
                if (diff < mindiff){
                    mindiff = diff;
                }
            }
            return;
        }
        dfs(index+1,totals,totalb,selectnum);
        dfs(index+1,totals*s[index],totalb+b[index],selectnum+1);
    }
}
